﻿Public Class mastypergt

    Private SDET = Nothing
    Private STATUS = Nothing

    'masmtypergt
    Private MTRGTID = Nothing
    Private MTRGTNAME = Nothing
    Private selectMasmtypergt = "SELECT `mtrgtid` as 'ID หมวด', `mtrgtname` as 'ชื่อหมวดคู่สัญญา', `sdet` as 'สถานะการมีรายการย่อย', `status` as 'สถานะการเปิดใช้งาน' FROM masmtypergt"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property MTRGTID_ As Integer
        Get
            Return MTRGTID
        End Get
        Set(value As Integer)
            MTRGTID = value
        End Set
    End Property

    Property MTRGTNAME_ As String
        Get
            Return MTRGTNAME
        End Get
        Set(value As String)
            MTRGTNAME = value
        End Set
    End Property

    Property SDET_ As Boolean
        Get
            Return SDET
        End Get
        Set(value As Boolean)
            If value = True Then
                SDET = 1
            Else
                SDET = 0
            End If
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasmtypergt_ As String
        Get
            Return selectMasmtypergt
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub masmtypergtCmb(ByVal comboboxName As ComboBox)
        Dim masmData As DataTable
        masmData = connect.GetTable("SELECT `mtrgtid`, `mtrgtname` FROM masmtypergt WHERE `status` = 1 AND `sdet` = 1")
        Try
            With comboboxName
                .DataSource = masmData
                .DisplayMember = "MTRGTNAME"
                .ValueMember = "MTRGTID"
                '.BindingContext = BindingContext
            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub insertMasmtypergtData()
        If TypeOf MTRGTNAME Is String Then
            If connect.GetTable("SELECT mtrgtid FROM masmtypergt WHERE mtrgtname = '" & MTRGTNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลหมวดคู่สัญญานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masmtypergt (mtrgtname, sdet, status) VALUES ('" & MTRGTNAME & "', '" & SDET & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลหมวดสิทธิ์เรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasmtypergtData()
        If TypeOf MTRGTNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masmtypergt SET mtrgtname = '" & MTRGTNAME & "', sdet = '" & SDET & "', status = '" & STATUS & "' WHERE mtrgtid = '" & MTRGTID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลหมวดคู่สัญญาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    'masstypergt

    Private STRGTID = Nothing
    Private stMTRGTID = Nothing
    Private STRGTNAME = Nothing
    Private selectMasstypergt = "SELECT a.`strgtid` AS 'ID กลุ่ม', b.`mtrgtname` AS 'ชื่อหมวดคู่สัญญา', a.`strgtname` AS 'ชื่อกลุ่มคู่สัญญา', a.`sdet` AS 'สถานะการมีรายการย่อย', a.`status` AS 'สถานะการเปิดใช้งาน', a.`mtrgtid` AS 'ID หมวดคู่สัญญา' FROM masstypergt a JOIN masmtypergt b ON a.mtrgtid = b.mtrgtid"

    Property STRGTID_() As Integer
        Get
            Return STRGTID
        End Get
        Set(value As Integer)
            STRGTID = value
        End Set
    End Property

    Property stMTRGTID_() As Integer
        Get
            Return stMTRGTID
        End Get
        Set(value As Integer)
            stMTRGTID = value
        End Set
    End Property

    Property STRGTNAME_() As String
        Get
            Return STRGTNAME
        End Get
        Set(value As String)
            STRGTNAME = value
        End Set
    End Property

    Property selectMasstypergt_() As String
        Get
            Return selectMasstypergt
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub masstypergtCmb(ByVal comboboxName As ComboBox)
        Dim massData As DataTable
        massData = connect.GetTable("SELECT `strgtid`, `strgtname` FROM masstypergt WHERE `status` = 1 AND `sdet` = 1")
        Try
            With comboboxName
                .DataSource = massData
                .DisplayMember = "MTRGTNAME"
                .ValueMember = "MTRGTID"
                '.BindingContext = BindingContext
            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub masstypergtCmb(MTRGTID As Integer, ByVal comboboxName As ComboBox)
        Dim massData As DataTable
        massData = connect.GetTable("SELECT `strgtid`, `strgtname` FROM masstypergt WHERE mtrgtid = '" & MTRGTID & "' AND (`status` = 1 AND `sdet` = 1)")
        Try
            With comboboxName
                .DataSource = massData
                .DisplayMember = "STRGTNAME"
                .ValueMember = "STRGTID"
                '.BindingContext = BindingContext.

            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub insertMasstypergtData()
        If TypeOf STRGTNAME Is String Then
            If connect.GetTable("SELECT STRGTID FROM masstypergt WHERE STRGTNAME = '" & STRGTNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลกลุ่มคู่สัญญานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masstypergt (MTRGTID, STRGTNAME, SDET, STATUS) VALUES ('" & stMTRGTID & "', '" & STRGTNAME & "','" & SDET & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลกลุ่มคู่สัญญาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasstypergtData()
        If TypeOf STRGTNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masstypergt SET MTRGTID = '" & stMTRGTID & "', STRGTNAME = '" & STRGTNAME & "', SDET = '" & SDET & "', STATUS = '" & STATUS & "' WHERE STRGTID = '" & STRGTID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลกลุ่มคู่สัญญาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Private SBRGTID = Nothing
    Private sbSTRGTID = Nothing
    Private SUBRGTNAME = Nothing
    Private selectMassubrgt = "SELECT c.`SBRGTID` AS 'ID สิทธิ์', a.`MTRGTNAME` AS 'ชื่อหมวดคู่สัญญา', b.`STRGTNAME` AS 'ชื่อกลุ่มคู่สัญญา', c.`SUBRGTNAME` AS 'ชื่อสิทธิ์', c.`STATUS` AS 'สถานะการเปิดใช้งาน', a.`MTRGTID` AS 'รหัสหมวด', b.`STRGTID` AS 'รหัสกลุ่ม' FROM massubrgt c JOIN masstypergt b ON c.STRGTID = b.STRGTID JOIN masmtypergt a ON b.MTRGTID = a.MTRGTID"

    Property SBRGTID_() As Integer
        Get
            Return SBRGTID
        End Get
        Set(value As Integer)
            SBRGTID = value
        End Set
    End Property

    Property sbSTRGTID_() As Integer
        Get
            Return sbSTRGTID
        End Get
        Set(value As Integer)
            sbSTRGTID = value
        End Set
    End Property

    Property SUBRGTNAME_() As String
        Get
            Return SUBRGTNAME
        End Get
        Set(value As String)
            SUBRGTNAME = value
        End Set
    End Property

    Property selectMassubrgt_() As String
        Get
            Return selectMassubrgt
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub massubrgtCmb(STRGTID As Integer, ByVal comboboxName As ComboBox)
        Dim massData As DataTable
        massData = connect.GetTable("SELECT `SBRGTID`, `SUBRGTNAME` FROM massubrgt WHERE `STRGTID` = '" & STRGTID & "' AND `STATUS` = 1")
        Try
            With comboboxName
                .DataSource = massData
                .DisplayMember = "SUBRGTNAME"
                .ValueMember = "SBRGTID"
                '.BindingContext = BindingContext.

            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub insertMassubrgtData()
        If TypeOf SUBRGTNAME Is String Then
            If connect.GetTable("SELECT SBRGTID FROM massubrgt WHERE SUBRGTNAME = '" & SUBRGTNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลสิทธิ์นี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO massubrgt (STRGTID, SUBRGTNAME, STATUS) VALUES ('" & sbSTRGTID & "', '" & SUBRGTNAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลสิทธิ์เรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMassubrgtData()
        If TypeOf SUBRGTNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE massubrgt SET STRGTID = '" & sbSTRGTID & "', SUBRGTNAME = '" & SUBRGTNAME & "', STATUS = '" & STATUS & "' WHERE SBRGTID = '" & SBRGTID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลสิทธิ์เรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Private PTRGTID = Nothing
    Private PTRGTNAME = Nothing
    Private ptMTRGTID = Nothing
    Private ptSTRGTID = Nothing
    Private ptSBRGTID = Nothing
    Private selectMasptypergt = "SELECT d.`PTRGTID` AS 'ID ประเภท', a.`MTRGTNAME` AS 'ชื่อหมวดคู่สัญญา', b.`STRGTNAME` AS 'ชื่อกลุ่มคู่สัญญา', c.`SUBRGTNAME` AS 'ชื่อสิทธิ์', d.`PTRGTNAME` AS 'ชื่อประเภท', d.`STATUS` AS 'สถานะการเปิดใช้งาน', a.`MTRGTID` AS 'รหัสหมวด', b.`STRGTID` AS 'รหัสกลุ่ม', c.`SBRGTID` AS 'รหัสสิทธิ์' FROM masptypergt d LEFT JOIN massubrgt c ON d.SBRGTID = c.SBRGTID LEFT JOIN masstypergt b ON d.STRGTID = b.STRGTID LEFT JOIN masmtypergt a ON d.MTRGTID = a.MTRGTID"
    'Private selectMasptypergt = "SELECT d.`PTRGTID` AS 'ID ประเภท', a.`MTRGTNAME` AS 'ชื่อหมวดคู่สัญญา', b.`STRGTNAME` AS 'ชื่อกลุ่มคู่สัญญา', c.`SUBRGTNAME` AS 'ชื่อสิทธิ์', d.`PTRGTNAME` AS 'ชื่อประเภท', d.`STATUS` AS 'สถานะการเปิดใช้งาน', a.`MTRGTID` AS 'รหัสหมวด', b.`STRGTID` AS 'รหัสกลุ่ม', c.`SBRGTID` AS 'รหัสสิทธิ์' FROM masptypergt d LEFT JOIN massubrgt c ON d.SBRGTID = c.SBRGTID LEFT JOIN masstypergt b ON c.STRGTID = b.STRGTID LEFT JOIN masmtypergt a ON b.MTRGTID = a.MTRGTID"

    Property PTRGTID_() As Integer
        Get
            Return PTRGTID
        End Get
        Set(value As Integer)
            PTRGTID = value
        End Set
    End Property

    Property PTRGTNAME_() As String
        Get
            Return PTRGTNAME
        End Get
        Set(value As String)
            PTRGTNAME = value
        End Set
    End Property

    Property ptMTRGTID_() As Integer
        Get
            Return ptMTRGTID
        End Get
        Set(value As Integer)
            ptMTRGTID = value
        End Set
    End Property

    Property ptSTRGTID_() As Integer
        Get
            Return ptSTRGTID
        End Get
        Set(value As Integer)
            ptSTRGTID = value
        End Set
    End Property

    Property ptSBRGTID_() As Integer
        Get
            Return ptSBRGTID
        End Get
        Set(value As Integer)
            ptSBRGTID = value
        End Set
    End Property

    Property selectMasptypergt_ As String
        Get
            Return selectMasptypergt
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasptypergtData()
        If TypeOf PTRGTNAME Is String Then
            If connect.GetTable("SELECT PTRGTID FROM masptypergt WHERE PTRGTNAME = '" & PTRGTNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลประเภทสิทธิ์นี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masptypergt (PTRGTNAME, MTRGTID, STRGTID, SBRGTID, STATUS) VALUES ('" & PTRGTNAME & "', '" & ptMTRGTID & "', '" & ptSTRGTID & "', '" & ptSBRGTID & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลประเภทสิทธิ์เรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasptypergtData()
        If TypeOf PTRGTNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masptypergt SET PTRGTNAME = '" & PTRGTNAME & "', MTRGTID = '" & ptMTRGTID & "', STRGTID = '" & ptSTRGTID & "', SBRGTID = '" & ptSBRGTID & "', STATUS = '" & STATUS & "' WHERE PTRGTID = '" & PTRGTID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลประเภทสิทธิ์เรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
